//package top.lzy.hive.utils;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.jdbc.core.JdbcTemplate;
//import top.lzy.hive.entity.Country;
//
//import java.sql.*;
//import java.util.ArrayList;
//import java.util.List;
//import javax.annotation.Resource;
//
//@Slf4j
//public class HiveUtils {
//    @Resource
//    private JdbcTemplate jdbcTemplate;
//    private static final String driverName = "org.apache.hive.jdbc.HiveDriver";
//    private static final String url = "jdbc:hive2://hadoop102:10000/default";
//    private static final String username = "zuijinx";
//    private static final String password = null;
//    public static List<Country> queryCountries() {
//        try {
//            Class.forName(driverName);
//            Connection conn = DriverManager.getConnection(url, username, password);
//            String sql = "select * from country";
//            PreparedStatement statement = conn.prepareStatement(sql);
//            ResultSet resultSet = statement.executeQuery();
//            List<Country> list = new ArrayList<>();
//            while (resultSet.next()) {
//                Country country = new Country();
//                country.setCaseNum(resultSet.getInt("case_num"));
//                country.setCc3(resultSet.getString("cc3"));
//                country.setCountry(resultSet.getString("country"));
//                country.setYear(resultSet.getInt("year"));
//                country.setSystemicCrisis(resultSet.getInt("systemic_crisis"));
//                country.setExchangeUsd(resultSet.getDouble("exchange_usd"));
//                country.setDomesticDebtInDefault(resultSet.getInt("domestic_debt_in_default"));
//                country.setSovereignExternalDebtDefault(resultSet.getInt("sovereign_external_debt_default"));
//                country.setGdpWeightedDefault(resultSet.getDouble("gdp_weighted_default"));
//                country.setInflationAnnualCpi(resultSet.getDouble("inflation_annual_cpi"));
//                country.setIndependence(resultSet.getInt("independence"));
//                country.setCurrencyCrises(resultSet.getInt("currency_crisis"));
//                country.setInflationCrises(resultSet.getInt("inflation_crises"));
//                country.setBankingCrisis(resultSet.getString("banking_crisis"));
//                country.setIsError(resultSet.getBoolean("is_error"));
//                country.setErrorMsg(resultSet.getString("error_msg"));
//                list.add(country);
//            }
//            conn.close();
//            statement.close();
//            return list;
//        } catch (ClassNotFoundException e) {
//            log.info("load driver failed", e);
//            throw new RuntimeException(e);
//        } catch (SQLException e) {
//            log.info("execute sql failed", e);
//            throw new RuntimeException(e);
//        }
//    }
//}
